package com.iflytek.bestsellers;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class BestSumReducer extends Reducer<Text, BestCountBean, Text, BestCountBean> {
    BestCountBean outValue = new BestCountBean();

    @Override
    protected void reduce(Text key, Iterable<BestCountBean> values, Context context) throws IOException, InterruptedException {
        long totalComments = 0;
        long totalPrices = 0;
        //累加统计
        for (BestCountBean value : values) {
            totalComments += value.getComments();
            totalPrices += value.getPrices();
        }

        outValue.set(totalComments, totalPrices);
        context.write(key, outValue);
    }
}